package com.yyq.sqlSession;

import com.yyq.config.XmlConfigureBuilder;
import com.yyq.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Author yuanyueqiang
 * @Date 2021-11-27 21:21
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory builder(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //1. dom4j解析配置文件,将解析出来的内容封装到Configuration中
        XmlConfigureBuilder configureBuilder = new XmlConfigureBuilder();
        Configuration configuration = configureBuilder.parseConfig(inputStream);
        //2. 创建SqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }

}
